package Java.BlackHorse.Thread.waitANDnotify;

public class Foodie extends Thread{
    @Override
    public void run() {
        while(true){
            synchronized (Dest.lock){
                if(Dest.count == 0){
                    break;
                }else{
                    if(Dest.foodFlag == 0){
                        try {
//                            没有面，等待厨师做面
                            Dest.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }else{
                        Dest.count--;
                        System.out.println("吃货吃了"+(10-Dest.count)+"碗面，还能吃"+Dest.count+"份面条");
//                        唤醒Dest.lock的所以线程
//                        唤醒厨师做面
                        Dest.lock.notifyAll();
                        Dest.foodFlag = 0;
                    }
                }
            }
        }
    }
}
